import { updateCustomerSubAccountStatus } from './api'
import { ElMessage, ElMessageBox } from 'element-plus'
import { DialogForm } from 'custom/index'

const stopDialog = new DialogForm('DialogForm')
stopDialog
  .title('停用子账号')
  .useGroup('')
    .useDatePicker('stopTime').label('停止日期').required().end()

export async function changeStatus(ctx) {
  const row = ctx.props.row
  // 停用 特殊处理
  if (row.status === 1) {
    const data: any = await stopDialog.open()
    updateCustomerSubAccountStatus({
      subAccountId: row.subAccountId,
      status: row.status === 1 ? 2 : 1,
      stopTime: data.stopTime
    }).then(() => {
      ElMessage.success('操作成功')
      ctx._c.dispatch('ListPage', 'getData')
    })
    return
  }
  await ElMessageBox.confirm(`是否确定${row.status === 1 ? '停用' : '启用'}子账号？`, '提示')
  updateCustomerSubAccountStatus({
    subAccountId: row.subAccountId,
    status: row.status === 1 ? 2 : 1
  }).then(() => {
    ElMessage.success('操作成功')
    ctx._c.dispatch('ListPage', 'getData')
  })
}
